home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / pengo.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  17KB  |  479 lines

  1. /***************************************************************************
  2.  
  3. Pengo memory map (preliminary)
  4.  
  5. driver by Nicola Salmoria
  6.  
  7. 0000-7fff ROM
  8. 8000-83ff Video RAM
  9. 8400-87ff Color RAM
  10. 8800-8fff RAM
  11.  
  12. memory mapped ports:
  13.  
  14. read:
  15. 9000      DSW1
  16. 9040      DSW0
  17. 9080      IN1
  18. 90c0      IN0
  19.  
  20. write:
  21. 8ff2-8ffd 6 pairs of two bytes:
  22.           the first byte contains the sprite image number (bits 2-7), Y flip (bit 0),
  23.           X flip (bit 1); the second byte the color
  24. 9005      sound voice 1 waveform (nibble)
  25. 9011-9013 sound voice 1 frequency (nibble)
  26. 9015      sound voice 1 volume (nibble)
  27. 900a      sound voice 2 waveform (nibble)
  28. 9016-9018 sound voice 2 frequency (nibble)
  29. 901a      sound voice 2 volume (nibble)
  30. 900f      sound voice 3 waveform (nibble)
  31. 901b-901d sound voice 3 frequency (nibble)
  32. 901f      sound voice 3 volume (nibble)
  33. 9022-902d Sprite coordinates, x/y pairs for 6 sprites
  34. 9040      interrupt enable
  35. 9041      sound enable
  36. 9042      palette bank selector
  37. 9043      flip screen
  38. 9044-9045 coin counters
  39. 9046      color lookup table bank selector
  40. 9047      character/sprite bank selector
  41. 9070      watchdog reset
  42.  
  43. Main clock: XTAL = 18.432 MHz
  44. Z80 Clock: XTAL/6 = 3.072 MHz
  45. Horizontal video frequency: HSYNC = XTAL/3/192/2 = 16 kHz
  46. Video frequency: VSYNC = HSYNC/132/2 = 60.606060 Hz
  47. VBlank duration: 1/VSYNC * (20/132) = 2500 us
  48.  
  49. ***************************************************************************/
  50.  
  51. #include "driver.h"
  52. #include "vidhrdw/generic.h"
  53.  
  54.  
  55.  
  56. void pengo_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom);
  57. WRITE_HANDLER( pengo_gfxbank_w );
  58. int pengo_vh_start(void);
  59. WRITE_HANDLER( pengo_flipscreen_w );
  60. void pengo_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  61.  
  62. extern unsigned char *pengo_soundregs;
  63. WRITE_HANDLER( pengo_sound_enable_w );
  64. WRITE_HANDLER( pengo_sound_w );
  65.  
  66. /* in machine/segacrpt.c */
  67. void pengo_decode(void);
  68.  
  69.  
  70.  
  71. static struct MemoryReadAddress readmem[] =
  72. {
  73.     { 0x0000, 0x7fff, MRA_ROM },
  74.     { 0x8000, 0x8fff, MRA_RAM },    /* video and color RAM, scratchpad RAM, sprite codes */
  75.     { 0x9000, 0x903f, input_port_3_r },    /* DSW1 */
  76.     { 0x9040, 0x907f, input_port_2_r },    /* DSW0 */
  77.     { 0x9080, 0x90bf, input_port_1_r },    /* IN1 */
  78.     { 0x90c0, 0x90ff, input_port_0_r },    /* IN0 */
  79.     { -1 }    /* end of table */
  80. };
  81.  
  82. static struct MemoryWriteAddress writemem[] =
  83. {
  84.     { 0x0000, 0x7fff, MWA_ROM },
  85.     { 0x8000, 0x83ff, videoram_w, &videoram, &videoram_size },
  86.     { 0x8400, 0x87ff, colorram_w, &colorram },
  87.     { 0x8800, 0x8fef, MWA_RAMROM },
  88.     { 0x8ff0, 0x8fff, MWA_RAM, &spriteram, &spriteram_size},
  89.     { 0x9000, 0x901f, pengo_sound_w, &pengo_soundregs },
  90.     { 0x9020, 0x902f, MWA_RAM, &spriteram_2 },
  91.     { 0x9040, 0x9040, interrupt_enable_w },
  92.     { 0x9041, 0x9041, pengo_sound_enable_w },
  93.     { 0x9042, 0x9042, MWA_NOP },
  94.     { 0x9043, 0x9043, pengo_flipscreen_w },
  95.     { 0x9044, 0x9046, MWA_NOP },
  96.     { 0x9047, 0x9047, pengo_gfxbank_w },
  97.     { 0x9070, 0x9070, MWA_NOP },
  98.     { -1 }    /* end of table */
  99. };
  100.  
  101.  
  102.  
  103. INPUT_PORTS_START( pengo )
  104.     PORT_START    /* IN0 */
  105.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_4WAY )
  106.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_4WAY )
  107.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_4WAY )
  108.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_4WAY )
  109.     /* the coin input must stay low for no less than 2 frames and no more */
  110.     /* than 9 frames to pass the self test check. */
  111.     /* Moreover, this way we avoid the game freezing until the user releases */
  112.     /* the "coin" key. */
  113.     PORT_BIT_IMPULSE( 0x10, IP_ACTIVE_LOW, IPT_COIN1, 2 )
  114.     PORT_BIT_IMPULSE( 0x20, IP_ACTIVE_LOW, IPT_COIN2, 2 )
  115.     /* Coin Aux doesn't need IMPULSE to pass the test, but it still needs it */
  116.     /* to avoid the freeze. */
  117.     PORT_BIT_IMPULSE( 0x40, IP_ACTIVE_LOW, IPT_COIN3, 2 )
  118.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 )
  119.  
  120.     PORT_START    /* IN1 */
  121.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_4WAY | IPF_COCKTAIL )
  122.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_4WAY | IPF_COCKTAIL )
  123.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_4WAY | IPF_COCKTAIL )
  124.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_4WAY | IPF_COCKTAIL )
  125.     PORT_BITX(0x10, IP_ACTIVE_LOW, IPT_SERVICE, DEF_STR( Service_Mode ), KEYCODE_F2, IP_JOY_NONE )
  126.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START1 )
  127.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START2 )
  128.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_COCKTAIL )
  129.  
  130.     PORT_START    /* DSW0 */
  131.     PORT_DIPNAME( 0x01, 0x00, DEF_STR( Bonus_Life ) )
  132.     PORT_DIPSETTING(    0x00, "30000" )
  133.     PORT_DIPSETTING(    0x01, "50000" )
  134.     PORT_DIPNAME( 0x02, 0x00, DEF_STR( Demo_Sounds ) )
  135.     PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
  136.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  137.     PORT_DIPNAME( 0x04, 0x00, DEF_STR( Cabinet ) )
  138.     PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
  139.     PORT_DIPSETTING(    0x04, DEF_STR( Cocktail ) )
  140.     PORT_DIPNAME( 0x18, 0x10, DEF_STR( Lives ) )
  141.     PORT_DIPSETTING(    0x18, "2" )
  142.     PORT_DIPSETTING(    0x10, "3" )
  143.     PORT_DIPSETTING(    0x08, "4" )
  144.     PORT_DIPSETTING(    0x00, "5" )
  145.     PORT_BITX(    0x20, 0x20, IPT_DIPSWITCH_NAME | IPF_CHEAT, "Rack Test", KEYCODE_F1, IP_JOY_NONE )
  146.     PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
  147.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  148.     PORT_DIPNAME( 0xc0, 0x80, DEF_STR( Difficulty ) )
  149.     PORT_DIPSETTING(    0xc0, "Easy" )
  150.     PORT_DIPSETTING(    0x80, "Medium" )
  151.     PORT_DIPSETTING(    0x40, "Hard" )
  152.     PORT_DIPSETTING(    0x00, "Hardest" )
  153.  
  154.     PORT_START    /* DSW1 */
  155.     PORT_DIPNAME( 0x0f, 0x0c, DEF_STR( Coin_A ) )
  156.     PORT_DIPSETTING(    0x00, DEF_STR( 4C_1C ) )
  157.     PORT_DIPSETTING(    0x08, DEF_STR( 3C_1C ) )
  158.     PORT_DIPSETTING(    0x04, DEF_STR( 2C_1C ) )
  159.     PORT_DIPSETTING(    0x09, "2 Coins/1 Credit 5/3" )
  160.     PORT_DIPSETTING(    0x05, "2 Coins/1 Credit 4/3" )
  161.     PORT_DIPSETTING(    0x0c, DEF_STR( 1C_1C ) )
  162.     PORT_DIPSETTING(    0x0d, "1 Coin/1 Credit 5/6" )
  163.     PORT_DIPSETTING(    0x03, "1 Coin/1 Credit 4/5" )
  164.     PORT_DIPSETTING(    0x0b, "1 Coin/1 Credit 2/3" )
  165.     PORT_DIPSETTING(    0x02, DEF_STR( 1C_2C ) )
  166.     PORT_DIPSETTING(    0x07, "1 Coin/2 Credits 5/11" )
  167.     PORT_DIPSETTING(    0x0f, "1 Coin/2 Credits 4/9" )
  168.     PORT_DIPSETTING(    0x0a, DEF_STR( 1C_3C ) )
  169.     PORT_DIPSETTING(    0x06, DEF_STR( 1C_4C ) )
  170.     PORT_DIPSETTING(    0x0e, DEF_STR( 1C_5C ) )
  171.     PORT_DIPSETTING(    0x01, DEF_STR( 1C_6C ) )
  172.     PORT_DIPNAME( 0xf0, 0xc0, DEF_STR( Coin_B ) )
  173.     PORT_DIPSETTING(    0x00, DEF_STR( 4C_1C ) )
  174.     PORT_DIPSETTING(    0x80, DEF_STR( 3C_1C ) )
  175.     PORT_DIPSETTING(    0x40, DEF_STR( 2C_1C ) )
  176.     PORT_DIPSETTING(    0x90, "2 Coins/1 Credit 5/3" )
  177.     PORT_DIPSETTING(    0x50, "2 Coins/1 Credit 4/3" )
  178.     PORT_DIPSETTING(    0xc0, DEF_STR( 1C_1C ) )
  179.     PORT_DIPSETTING(    0xd0, "1 Coin/1 Credit 5/6" )
  180.     PORT_DIPSETTING(    0x30, "1 Coin/1 Credit 4/5" )
  181.     PORT_DIPSETTING(    0xb0, "1 Coin/1 Credit 2/3" )
  182.     PORT_DIPSETTING(    0x20, DEF_STR( 1C_2C ) )
  183.     PORT_DIPSETTING(    0x70, "1 Coin/2 Credits 5/11" )
  184.     PORT_DIPSETTING(    0xf0, "1 Coin/2 Credits 4/9" )
  185.     PORT_DIPSETTING(    0xa0, DEF_STR( 1C_3C ) )
  186.     PORT_DIPSETTING(    0x60, DEF_STR( 1C_4C ) )
  187.     PORT_DIPSETTING(    0xe0, DEF_STR( 1C_5C ) )
  188.     PORT_DIPSETTING(    0x10, DEF_STR( 1C_6C ) )
  189. INPUT_PORTS_END
  190.  
  191.  
  192.  
  193. static struct GfxLayout tilelayout =
  194. {
  195.     8,8,    /* 8*8 characters */
  196.     256,    /* 256 characters */
  197.     2,  /* 2 bits per pixel */
  198.     { 0, 4 },   /* the two bitplanes for 4 pixels are packed into one byte */
  199.     { 8*8+0, 8*8+1, 8*8+2, 8*8+3, 0, 1, 2, 3 }, /* bits are packed in groups of four */
  200.     { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
  201.     16*8    /* every char takes 16 bytes */
  202. };
  203.  
  204.  
  205. static struct GfxLayout spritelayout =
  206. {
  207.     16,16,    /* 16*16 sprites */
  208.     64,    /* 64 sprites */
  209.     2,    /* 2 bits per pixel */
  210.     { 0, 4 },    /* the two bitplanes for 4 pixels are packed into one byte */
  211.     { 8*8, 8*8+1, 8*8+2, 8*8+3, 16*8+0, 16*8+1, 16*8+2, 16*8+3,
  212.             24*8+0, 24*8+1, 24*8+2, 24*8+3, 0, 1, 2, 3 },
  213.     { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
  214.             32*8, 33*8, 34*8, 35*8, 36*8, 37*8, 38*8, 39*8 },
  215.     64*8    /* every sprite takes 64 bytes */
  216. };
  217.  
  218. static struct GfxDecodeInfo gfxdecodeinfo[] =
  219. {
  220.     { REGION_GFX1, 0x0000, &tilelayout,      0, 32 },  /* first bank */
  221.     { REGION_GFX1, 0x1000, &spritelayout,    0, 32 },
  222.     { REGION_GFX2, 0x0000, &tilelayout,   4*32, 32 },  /* second bank */
  223.     { REGION_GFX2, 0x1000, &spritelayout, 4*32, 32 },
  224.     { -1 } /* end of array */
  225. };
  226.  
  227.  
  228. static struct namco_interface namco_interface =
  229. {
  230.     3072000/32,    /* sample rate */
  231.     3,            /* number of voices */
  232.     100,        /* playback volume */
  233.     REGION_SOUND1    /* memory region */
  234. };
  235.  
  236.  
  237.  
  238. static struct MachineDriver machine_driver_pengo =
  239. {
  240.     /* basic machine hardware */
  241.     {
  242.         {
  243.             CPU_Z80,
  244. /*            18432000/6,    * 3.072 Mhz */
  245.             3020000,    /* The correct speed is 3.072 Mhz, but 3.020 gives a more */
  246.                         /* accurate emulation speed (time for two attract mode */
  247.                         /* cycles after power up, until the high score list appears */
  248.                         /* for the second time: 3'39") */
  249.             readmem,writemem,0,0,
  250.             interrupt,1
  251.         }
  252.     },
  253.     60, 2500,    /* frames per second, vblank duration */
  254.     1,    /* single CPU, no need for interleaving */
  255.     0,
  256.  
  257.     /* video hardware */
  258.     36*8, 28*8, { 0*8, 36*8-1, 0*8, 28*8-1 },
  259.     gfxdecodeinfo,
  260.     32,4*64,
  261.     pengo_vh_convert_color_prom,
  262.  
  263.     VIDEO_TYPE_RASTER | VIDEO_SUPPORTS_DIRTY,
  264.     0,
  265.     pengo_vh_start,
  266.     generic_vh_stop,
  267.     pengo_vh_screenrefresh,
  268.  
  269.     /* sound hardware */
  270.     0,0,0,0,
  271.     {
  272.         {
  273.             SOUND_NAMCO,
  274.             &namco_interface
  275.         }
  276.     }
  277. };
  278.  
  279.  
  280.  
  281. /***************************************************************************
  282.  
  283.   Game driver(s)
  284.  
  285. ***************************************************************************/
  286.  
  287. ROM_START( pengo )
  288.     ROM_REGION( 2*0x10000, REGION_CPU1 )     /* 64k for code + 64k for decrypted opcodes */
  289.     ROM_LOAD( "ic8",          0x0000, 0x1000, 0xf37066a8 )
  290.     ROM_LOAD( "ic7",          0x1000, 0x1000, 0xbaf48143 )
  291.     ROM_LOAD( "ic15",         0x2000, 0x1000, 0xadf0eba0 )
  292.     ROM_LOAD( "ic14",         0x3000, 0x1000, 0xa086d60f )
  293.     ROM_LOAD( "ic21",         0x4000, 0x1000, 0xb72084ec )
  294.     ROM_LOAD( "ic20",         0x5000, 0x1000, 0x94194a89 )
  295.     ROM_LOAD( "ic32",         0x6000, 0x1000, 0xaf7b12c4 )
  296.     ROM_LOAD( "ic31",         0x7000, 0x1000, 0x933950fe )
  297.  
  298.     ROM_REGION( 0x2000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  299.     ROM_LOAD( "ic92",         0x0000, 0x2000, 0xd7eec6cd )
  300.  
  301.     ROM_REGION( 0x2000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  302.     ROM_LOAD( "ic105",        0x0000, 0x2000, 0x5bfd26e9 )
  303.  
  304.     ROM_REGION( 0x0420, REGION_PROMS )
  305.     ROM_LOAD( "pr1633.078",   0x0000, 0x0020, 0x3a5844ec )
  306.     ROM_LOAD( "pr1634.088",   0x0020, 0x0400, 0x766b139b )
  307.  
  308.     ROM_REGION( 0x0200, REGION_SOUND1 )    /* sound PROMs */
  309.     ROM_LOAD( "pr1635.051",   0x0000, 0x0100, 0xc29dea27 )
  310.     ROM_LOAD( "pr1636.070",   0x0100, 0x0100, 0x77245b66 )    /* timing - not used */
  311. ROM_END
  312.  
  313. ROM_START( pengo2 )
  314.     ROM_REGION( 2*0x10000, REGION_CPU1 )     /* 64k for code + 64k for decrypted opcodes */
  315.     ROM_LOAD( "ic8.2",        0x0000, 0x1000, 0xe4924b7b )
  316.     ROM_LOAD( "ic7.2",        0x1000, 0x1000, 0x72e7775d )
  317.     ROM_LOAD( "ic15.2",       0x2000, 0x1000, 0x7410ef1e )
  318.     ROM_LOAD( "ic14.2",       0x3000, 0x1000, 0x55b3f379 )
  319.     ROM_LOAD( "ic21",         0x4000, 0x1000, 0xb72084ec )
  320.     ROM_LOAD( "ic20.2",       0x5000, 0x1000, 0x770570cf )
  321.     ROM_LOAD( "ic32",         0x6000, 0x1000, 0xaf7b12c4 )
  322.     ROM_LOAD( "ic31.2",       0x7000, 0x1000, 0x669555c1 )
  323.  
  324.     ROM_REGION( 0x2000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  325.     ROM_LOAD( "ic92",         0x0000, 0x2000, 0xd7eec6cd )
  326.  
  327.     ROM_REGION( 0x2000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  328.     ROM_LOAD( "ic105",        0x0000, 0x2000, 0x5bfd26e9 )
  329.  
  330.     ROM_REGION( 0x0420, REGION_PROMS )
  331.     ROM_LOAD( "pr1633.078",   0x0000, 0x0020, 0x3a5844ec )
  332.     ROM_LOAD( "pr1634.088",   0x0020, 0x0400, 0x766b139b )
  333.  
  334.     ROM_REGION( 0x0200, REGION_SOUND1 )    /* sound PROMs */
  335.     ROM_LOAD( "pr1635.051",   0x0000, 0x0100, 0xc29dea27 )
  336.     ROM_LOAD( "pr1636.070",   0x0100, 0x0100, 0x77245b66 )    /* timing - not used */
  337. ROM_END
  338.  
  339. ROM_START( pengo2u )
  340.     ROM_REGION( 0x10000, REGION_CPU1 )    /* 64k for code */
  341.     ROM_LOAD( "pengo.u8",     0x0000, 0x1000, 0x3dfeb20e )
  342.     ROM_LOAD( "pengo.u7",     0x1000, 0x1000, 0x1db341bd )
  343.     ROM_LOAD( "pengo.u15",    0x2000, 0x1000, 0x7c2842d5 )
  344.     ROM_LOAD( "pengo.u14",    0x3000, 0x1000, 0x6e3c1f2f )
  345.     ROM_LOAD( "pengo.u21",    0x4000, 0x1000, 0x95f354ff )
  346.     ROM_LOAD( "pengo.u20",    0x5000, 0x1000, 0x0fdb04b8 )
  347.     ROM_LOAD( "pengo.u32",    0x6000, 0x1000, 0xe5920728 )
  348.     ROM_LOAD( "pengo.u31",    0x7000, 0x1000, 0x13de47ed )
  349.  
  350.     ROM_REGION( 0x2000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  351.     ROM_LOAD( "ic92",         0x0000, 0x2000, 0xd7eec6cd )
  352.  
  353.     ROM_REGION( 0x2000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  354.     ROM_LOAD( "ic105",        0x0000, 0x2000, 0x5bfd26e9 )
  355.  
  356.     ROM_REGION( 0x0420, REGION_PROMS )
  357.     ROM_LOAD( "pr1633.078",   0x0000, 0x0020, 0x3a5844ec )
  358.     ROM_LOAD( "pr1634.088",   0x0020, 0x0400, 0x766b139b )
  359.  
  360.     ROM_REGION( 0x0200, REGION_SOUND1 )    /* sound PROMs */
  361.     ROM_LOAD( "pr1635.051",   0x0000, 0x0100, 0xc29dea27 )
  362.     ROM_LOAD( "pr1636.070",   0x0100, 0x0100, 0x77245b66 )    /* timing - not used */
  363. ROM_END
  364.  
  365. ROM_START( penta )
  366.     ROM_REGION( 2*0x10000, REGION_CPU1 )     /* 64k for code + 64k for decrypted opcodes */
  367.     ROM_LOAD( "008_pn01.bin", 0x0000, 0x1000, 0x22f328df )
  368.     ROM_LOAD( "007_pn05.bin", 0x1000, 0x1000, 0x15bbc7d3 )
  369.     ROM_LOAD( "015_pn02.bin", 0x2000, 0x1000, 0xde82b74a )
  370.     ROM_LOAD( "014_pn06.bin", 0x3000, 0x1000, 0x160f3836 )
  371.     ROM_LOAD( "021_pn03.bin", 0x4000, 0x1000, 0x7824e3ef )
  372.     ROM_LOAD( "020_pn07.bin", 0x5000, 0x1000, 0x377b9663 )
  373.     ROM_LOAD( "032_pn04.bin", 0x6000, 0x1000, 0xbfde44c1 )
  374.     ROM_LOAD( "031_pn08.bin", 0x7000, 0x1000, 0x64e8c30d )
  375.  
  376.     ROM_REGION( 0x2000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  377.     ROM_LOAD( "092_pn09.bin", 0x0000, 0x2000, 0x6afeba9d )
  378.  
  379.     ROM_REGION( 0x2000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  380.     ROM_LOAD( "ic105",        0x0000, 0x2000, 0x5bfd26e9 )
  381.  
  382.     ROM_REGION( 0x0420, REGION_PROMS )
  383.     ROM_LOAD( "pr1633.078",   0x0000, 0x0020, 0x3a5844ec )
  384.     ROM_LOAD( "pr1634.088",   0x0020, 0x0400, 0x766b139b )
  385.  
  386.     ROM_REGION( 0x0200, REGION_SOUND1 )    /* sound PROMs */
  387.     ROM_LOAD( "pr1635.051",   0x0000, 0x0100, 0xc29dea27 )
  388.     ROM_LOAD( "pr1636.070",   0x0100, 0x0100, 0x77245b66 )    /* timing - not used */
  389. ROM_END
  390.  
  391.  
  392.  
  393. static void init_pengo(void)
  394. {
  395.     pengo_decode();
  396. }
  397.  
  398. static void init_penta(void)
  399. {
  400. /*
  401.     the values vary, but the translation mask is always laid out like this:
  402.  
  403.       0 1 2 3 4 5 6 7 8 9 a b c d e f
  404.     0 A A B B A A B B C C D D C C D D
  405.     1 A A B B A A B B C C D D C C D D
  406.     2 E E F F E E F F G G H H G G H H
  407.     3 E E F F E E F F G G H H G G H H
  408.     4 A A B B A A B B C C D D C C D D
  409.     5 A A B B A A B B C C D D C C D D
  410.     6 E E F F E E F F G G H H G G H H
  411.     7 E E F F E E F F G G H H G G H H
  412.     8 H H G G H H G G F F E E F F E E
  413.     9 H H G G H H G G F F E E F F E E
  414.     a D D C C D D C C B B A A B B A A
  415.     b D D C C D D C C B B A A B B A A
  416.     c H H G G H H G G F F E E F F E E
  417.     d H H G G H H G G F F E E F F E E
  418.     e D D C C D D C C B B A A B B A A
  419.     f D D C C D D C C B B A A B B A A
  420.  
  421.     (e.g. 0xc0 is XORed with H)
  422.     therefore in the following tables we only keep track of A, B, C, D, E, F, G and H.
  423. */
  424.     static const unsigned char data_xortable[2][8] =
  425.     {
  426.         { 0xa0,0x82,0x28,0x0a,0x82,0xa0,0x0a,0x28 },    /* ...............0 */
  427.         { 0x88,0x0a,0x82,0x00,0x88,0x0a,0x82,0x00 }        /* ...............1 */
  428.     };
  429.     static const unsigned char opcode_xortable[8][8] =
  430.     {
  431.         { 0x02,0x08,0x2a,0x20,0x20,0x2a,0x08,0x02 },    /* ...0...0...0.... */
  432.         { 0x88,0x88,0x00,0x00,0x88,0x88,0x00,0x00 },    /* ...0...0...1.... */
  433.         { 0x88,0x0a,0x82,0x00,0xa0,0x22,0xaa,0x28 },    /* ...0...1...0.... */
  434.         { 0x88,0x0a,0x82,0x00,0xa0,0x22,0xaa,0x28 },    /* ...0...1...1.... */
  435.         { 0x2a,0x08,0x2a,0x08,0x8a,0xa8,0x8a,0xa8 },    /* ...1...0...0.... */
  436.         { 0x2a,0x08,0x2a,0x08,0x8a,0xa8,0x8a,0xa8 },    /* ...1...0...1.... */
  437.         { 0x88,0x0a,0x82,0x00,0xa0,0x22,0xaa,0x28 },    /* ...1...1...0.... */
  438.         { 0x88,0x0a,0x82,0x00,0xa0,0x22,0xaa,0x28 }        /* ...1...1...1.... */
  439.     };
  440.     int A;
  441.     unsigned char *rom = memory_region(REGION_CPU1);
  442.     int diff = memory_region_length(REGION_CPU1) / 2;
  443.  
  444.  
  445.     memory_set_opcode_base(0,rom+diff);
  446.  
  447.     for (A = 0x0000;A < 0x8000;A++)
  448.     {
  449.         int i,j;
  450.         unsigned char src;
  451.  
  452.  
  453.         src = rom[A];
  454.  
  455.         /* pick the translation table from bit 0 of the address */
  456.         i = A & 1;
  457.  
  458.         /* pick the offset in the table from bits 1, 3 and 5 of the source data */
  459.         j = ((src >> 1) & 1) + (((src >> 3) & 1) << 1) + (((src >> 5) & 1) << 2);
  460.         /* the bottom half of the translation table is the mirror image of the top */
  461.         if (src & 0x80) j = 7 - j;
  462.  
  463.         /* decode the ROM data */
  464.         rom[A] = src ^ data_xortable[i][j];
  465.  
  466.         /* now decode the opcodes */
  467.         /* pick the translation table from bits 4, 8 and 12 of the address */
  468.         i = ((A >> 4) & 1) + (((A >> 8) & 1) << 1) + (((A >> 12) & 1) << 2);
  469.         rom[A + diff] = src ^ opcode_xortable[i][j];
  470.     }
  471. }
  472.  
  473.  
  474.  
  475. GAME( 1982, pengo,   0,     pengo, pengo, pengo, ROT90, "Sega", "Pengo (set 1)" )
  476. GAME( 1982, pengo2,  pengo, pengo, pengo, pengo, ROT90, "Sega", "Pengo (set 2)" )
  477. GAME( 1982, pengo2u, pengo, pengo, pengo, 0,     ROT90, "Sega", "Pengo (set 2 not encrypted)" )
  478. GAME( 1982, penta,   pengo, pengo, pengo, penta, ROT90, "bootleg", "Penta" )
  479.